package com.yima.baseproj.module.app.user;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yima.baseproj.module.app.user.model.AppUserSearchVo;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;

@Service
public class AppUserService extends ServiceImpl<AppUserMapper, AppUserEntity> {

    public AppUserEntity findByMpWeixinOpenId(String mpWeixinOpenId) {
        return getOne(Wrappers.<AppUserEntity>query().eq("mp_weixin_open_id",mpWeixinOpenId));
    }

    public Page<LinkedHashMap> findByPage(Page page, AppUserSearchVo appUserSearchVo) {
        return baseMapper.findBySearchVo(page, appUserSearchVo);
    }

    public List<LinkedHashMap> findByList(AppUserSearchVo appUserSearchVo) {
        return baseMapper.findBySearchVo(appUserSearchVo);
    }

    public AppUserEntity findByMaxNo() {
        return baseMapper.selectOne(new LambdaQueryWrapper<AppUserEntity>().orderByDesc(AppUserEntity::getUserNo).last("limit 1"));
    }
}
